package drive.Service.ServiceFormat;

import com.google.gson.Gson;
import drive.Mapper.ArticleImageMapper;
import drive.Model.ArticleImage;
import drive.Service.ServiceInterface.ArticleImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleImageServiceA implements ArticleImageService {

    @Autowired
    private ArticleImageMapper articleImageMapper;

    private Gson gson = new Gson();

    @Override
    public String findAll() {
        List<ArticleImage> list = articleImageMapper.findAll();
        return gson.toJson(list);
    }

    @Override
    public String findByArticleID(Integer articleID) {
        List<ArticleImage> list = articleImageMapper.findByArticleID(articleID);
        return gson.toJson(list);
    }

    @Override
    public String findByImageID(Integer imageID) {
        List<ArticleImage> list = articleImageMapper.findByImageID(imageID);
        return gson.toJson(list);
    }

    @Override
    public String add(ArticleImage articleImage) {
        int result = articleImageMapper.add(articleImage);
        return "添加文章图片关联成功";
    }

    @Override
    public String delete(Integer articleID, Integer imageID) {
        int result = articleImageMapper.delete(articleID, imageID);
        return "删除文章图片关联成功";
    }
}